package com.andgee.persist;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ConvertToPersist {
	//converting Whatever to byte[]
	public byte[] getByteArrayObject(Whatever w){
		   
        byte[] byteArrayObject = null;
        try {
           
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(w);
           
            oos.close();
            bos.close();
            byteArrayObject = bos.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
            return byteArrayObject;
        }
        return byteArrayObject;
    }
    //converting byte[] to Whatever
    public Whatever getJavaObject(byte[] convertObject){
            Whatever w = null;
           
            ByteArrayInputStream bais;
            ObjectInputStream ins;
            try {
           
            bais = new ByteArrayInputStream(convertObject);
           
            ins = new ObjectInputStream(bais);
            w =(Whatever)ins.readObject();
           
            ins.close();

            }
            catch (Exception e) {
            e.printStackTrace();
            }
            return w;
    }
 
}
